package com.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BigWheelDrawUtil {


    /**
     * 给转盘的每个角度赋初始值
     *
     * @return
     */
    private final static List<WchatLotteryDomain> initDrawList = new ArrayList<WchatLotteryDomain>() {{
        add(new WchatLotteryDomain(1, "200", 1));
        add(new WchatLotteryDomain(2, "100", 99));
    }};

    /**
     * 生成奖项
     *
     * @return
     */
    public static WchatLotteryDomain generateAward() {
        List<WchatLotteryDomain> initData = initDrawList;
        long result = randomnum(1, 100);
        int line = 0;
        int temp = 0;
        WchatLotteryDomain returnobj = null;
        int index = 0;
        for (int i = 0; i < initDrawList.size(); i++) {
            WchatLotteryDomain obj2 = initDrawList.get(i);
            int c = obj2.getV();
            temp = temp + c;
            line = 100 - temp;
            if (c != 0) {
                if (result > line && result <= (line + c)) {
                    returnobj = obj2;
                    break;
                }
            }
        }
        return returnobj;
    }

    // 获取2个值之间的随机数
    private static long randomnum(int smin, int smax) {
        int range = smax - smin;
        double rand = Math.random();
        return (smin + Math.round(rand * range));
    }


    public static void main(String[] args) {

        Map<Integer, Integer> count = new HashMap<>();
        for(int i=0;i<10000;i++){
            WchatLotteryDomain domain = generateAward();

            count.put(domain.getId(),count.get(domain.getId())==null?1:count.get(domain.getId())+1);
        }
        for (Map.Entry<Integer, Integer> entry : count.entrySet()) {
            System.out.println("xx:"+entry.getKey()+ ", 命中次数=" + entry.getValue() + ", 实际概率="
                    + entry.getValue() / 10000D);
        }
    }

}